//
//  LCFileManager.m
//  油递员(车队端)
//
//  Created by puman on 16/3/31.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "LCFileManager.h"

@implementation LCFileManager

+ (LCFileManager *)shareHandle{
    
    static LCFileManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (manager == nil) {
            manager = [[LCFileManager alloc] init];
            manager.userDefaults = [NSUserDefaults standardUserDefaults];
        }
    });
    
    return manager;
}
// 加密的方法
+ (NSString *)getMD5WithString:(NSString *)time{
    NSString *public_key = @"youin_app";
    NSString *string = [NSString stringWithFormat:@"%@&%@&%@",@"私钥",@"公钥",time];
    const char *cStr = [string UTF8String];
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    CC_MD5( cStr, strlen(cStr), digest );
    NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
        [result appendFormat:@"%02x", digest[i]];
    return result;
    
}
// 得到时间戳的方法
+ (NSString *)getTimesTamp{
    NSTimeInterval time = [[NSDate date] timeIntervalSince1970] * 1000;
    
    double date = (double)time;
    NSString *timeStr = [NSString stringWithFormat:@"%.0f",date];
    return timeStr;
}
// 判断网络状态的方法
+ (BOOL)isNetwork{
    Reachability *reachability = [Reachability reachabilityWithHostname:@"www.apple.com"];
    switch ([reachability currentReachabilityStatus]) {
        case NotReachable:
            return YES;
            break;
        case ReachableViaWWAN:
            return NO;
            break;
        case ReachableViaWiFi:
            return NO;
            break;
            
        default:
            break;
    }
    
}
+ (UIImage*)imageWithSize:(CGSize)size borderColor:(UIColor *)color borderWidth:(CGFloat)borderWidth
{
    UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
    [[UIColor clearColor] set];
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextBeginPath(context);
    CGContextSetLineWidth(context, borderWidth);
    CGContextSetStrokeColorWithColor(context, color.CGColor);
    CGFloat lengths[] = { 3, 1 };
    CGContextSetLineDash(context, 0, lengths, 1);
    CGContextMoveToPoint(context, 0.0, 0.0);
    CGContextAddLineToPoint(context, size.width, 0.0);
    CGContextAddLineToPoint(context, size.width, size.height);
    CGContextAddLineToPoint(context, 0, size.height);
    CGContextAddLineToPoint(context, 0.0, 0.0);
    CGContextStrokePath(context);
    UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
- (void)saveVale:(id)value forKey:(NSString *)key{
    [self.userDefaults setObject:value forKey:key];
    [self.userDefaults synchronize];
}
- (id)getValeForKey:(NSString *)key{
    id value = [self.userDefaults objectForKey:key];
    return value;
}

@end
